home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue52 / HTML / Code / AppServer / mlePropertyInfo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-10-24  |  1.3 KB  |  70 lines

  1. unit mlePropertyInfo;
  2.  
  3. interface
  4.  
  5. uses
  6.   DB, DBTables, dpoBase;
  7.  
  8. type
  9.   TPropertyInfo = class
  10.   private
  11.     FPropertyName: string;
  12.   protected
  13.     Field: TField;
  14.     function GetDatatype: TFieldType;
  15.     function GetSize: Integer;
  16.     procedure SetPropertyName(aValue: string);
  17.   public
  18.     Instance: TDataObject;
  19.     function GetValue: Variant;
  20.     function AsString: string;
  21.     property DataType: TFieldType read GetDataType;
  22.     property PropertyName: string read FPropertyName write SetPropertyName;
  23.     property Size: Integer read GetSize;
  24.   end;
  25.  
  26. implementation
  27.  
  28. uses
  29.   SysUtils;
  30.  
  31. { TPropertyInfo }
  32.  
  33. function TPropertyInfo.AsString: string;
  34. begin
  35.   case Datatype of
  36.     ftCurrency:
  37.       Result := FormatFloat('0.00', GetValue);
  38.     ftTime:
  39.       Result := FormatDateTime(ShortTimeFormat, GetValue);
  40.     else
  41.       Result := GetValue;
  42.   end;
  43. end;
  44.  
  45. function TPropertyInfo.GetDatatype: TFieldType;
  46. begin
  47.   Result := Field.DataType;
  48. end;
  49.  
  50. function TPropertyInfo.GetSize: Integer;
  51. begin
  52.   Result := Field.Size;
  53. end;
  54.  
  55. function TPropertyInfo.GetValue: Variant;
  56. begin
  57.   Result := Field.AsVariant;
  58. end;
  59.  
  60. procedure TPropertyInfo.SetPropertyName(aValue: string);
  61. begin
  62.   if FPropertyName <> aValue then
  63.   begin
  64.     FPropertyName := aValue;
  65.     Field := Instance.PropertyByName(PropertyName);
  66.   end;
  67. end;
  68.  
  69. end.
  70.